package com.pikaqiu.warehouse.service.impl;

import com.pikaqiu.warehouse.config.WeChatConfig;
import com.pikaqiu.warehouse.domain.common.ReqCommonParams;
import com.pikaqiu.warehouse.service.CommonService;
import com.pikaqiu.warehouse.service.UserService;
import com.pikaqiu.warehouse.utils.FileUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @Author: Administrator
 * @Date: 2024/8/15
 */
@Service
public class CommonServiceImpl implements CommonService {

    @Resource
    private WeChatConfig weChatConfig;

    @Resource
    private UserService userService;

    @Override
    public String uploadImage(String type, MultipartFile file) {
        ReqCommonParams reqCommonParams = userService.checkUser();;
        String filePath = "%s/%s/%s/%s";
        filePath = String.format(filePath, weChatConfig.getDefaultPath(), weChatConfig.getImagePath(), type,
            reqCommonParams.getCompanyCode());
        String fileName = FileUtils.upload(filePath, file);
        return String.format("%s/%s%s/%s/%s", weChatConfig.getDomain(), weChatConfig.getImagePath(), type,
            reqCommonParams.getCompanyCode(), fileName);
    }
}
